package com.example.service.impl;

import com.example.annotation.RedisCache;
import com.example.dao.UserDao;
import com.example.entity.User;
import com.example.service.UserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;


/**
 * @Author: John
 * @Date 2019/7/20 10:45
 */
@Service("userService")
@Transactional(rollbackFor = Exception.class)
public class UserServiceImpl implements UserService {

    @Resource
    UserDao userDao;

    @Override
    public User getById(int id) {
        return userDao.getById(id);
    }

    @RedisCache(value = "user#{0}")
    @Override
    public User getByName(String userName) {
        User user = userDao.getByName(userName);
        if (user != null) {
            return user;
        } else {
            return null;
        }
    }

    @Override
    public void insert(User user) {
//        userDao.insert(user);
    }

    @Override
    public List<User> getUsersByRoleID(int roleID) {
        return userDao.getUsersByRoleID(roleID);
    }
}
